<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-table v-loading="loading" :data="managementList">
          <el-table-column fixed label="序号" prop="" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="企业名称" align="left" key="companyName" prop="companyName" />
          <el-table-column label="关联省份名称" align="left" key="provinceName" prop="provinceName" />
          <el-table-column label="创建时间" align="left" key="createTime" prop="createTime" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['taxmsg:management:provinceConfigUpdate']"
              >修改关联省份</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="企业名称" prop="companyName">
              <el-input v-model="form.companyName" placeholder="请输入企业名称" disabled/>
            </el-form-item>
            <el-form-item label="完税省份" prop="provinceCode">
              <el-select v-model="form.provinceCode" value-key="provinceCode" placeholder="全部" clearable size="small" filterable @change="change">
                <el-option
                  v-for="dict in provinceOptions"
                  :key="dict.provinceCode"
                  :label="dict.provinceFullName"
                  :value="dict.provinceCode"
                />
              </el-select>
            </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { managementList, provinceConfigUpdate } from "@/api/taxmsg/management";
export default {
  name: "Management",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户表格数据
      managementList: null,
      // 省份信息数据字典
      provinceOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20
      },
      // 表单校验
      rules: {
        companyName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        provinceCode: [
          { required: true, message: "请选择完税省份", trigger: "blur" }
        ]
      },
    };
  },
  watch: {
    
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      managementList(this.queryParams).then(response => {
          this.managementList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    change(){
      this.$forceUpdate();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        companyId: undefined,
        provinceCode: undefined
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      // const id = row.companyId;
      this.open = true;
      this.title = "修改关联省份";
      this.form.companyName = row.companyName;
      this.form.companyId = row.companyId;
      this.getProvince().then(response => {
        this.provinceOptions = response.data;
      });
      this.form.provinceCode = row.provinceCode;
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          provinceConfigUpdate(this.form).then(response => {
              this.msgSuccess(response.msg);
              this.open = false;
              this.getList();
            });
        }
      });
    }
  }
};
</script>